#ifndef _particlesystem_h_included_
#define _particlesystem_h_included_
#include <d3dx9.h>
#include <d3d9.h>
#include <string>
#include <Vector>
//#include <Math.h>
#include "Game.h"
#include "Model.h"
#include "ModelPrimitive.h"
#include <D3dx9math.h>
#include <ctime>    // For time()
#include <cstdlib>

using namespace std;

struct ExplosionNode{
	D3DXVECTOR3* Pos;
	D3DXVECTOR3* Dir;
	D3DXVECTOR3* Speed;
	D3DXCOLOR* Color;
	float TimeRemaining;
};

//This class is responsible for maintaining the state
//of a model
class ParticleSystem : public ModelPrimitive
{
	protected:
	string* mName;
	float mDecayRate;
	float mExpandRate;
	float mPower;
	float mSpawnScale;
	bool ini;
	Model* mModel;
	bool mDone;
	float mDelay;
	float mtime;
	int mMaxDepth;
	
	

	vector<ExplosionNode*> * mNodes;
	vector<ExplosionNode*> * mTemp;
	
	public:
	
	float radius;
	float mLifeTime;
	float cosine;
	int generator;

	ParticleSystem();
	void Update(LPDIRECT3DDEVICE9 d3ddev, double pElapsed, double pTotal);;
	void Draw(LPDIRECT3DDEVICE9 d3ddev);
	void Reset();
	void Reset(float pRadius, float pLifetime, float pCosine, int pGenerator);
	
	D3DXVECTOR3* CalcNewNode(D3DXVECTOR3* pos, float power);

	string* GetName(){return mName;}
	void SetName(string* pName){mName = pName;}
	float GetDecayRate(){return mDecayRate;}
	void SetDecayRate(float pDecayRate){mDecayRate = pDecayRate;}
	float GetPower(){return mPower;}
	void SetPower(float pPower){mPower = pPower;}
	float GetSpawnScale(){return mSpawnScale;}
	void SetSpawnScale(float pScale){mSpawnScale = pScale;}
	void SetModel(Model* pModel){mModel = pModel;}
	float Random(){
	/*	int rand = ::rand()% 100 /10.0f;
		for(int a =0; a <rand; a++){
			::rand();
		}*/
		return ((::rand()% 100)/100.0f);
	}

	bool GetDone(){return mDone;}
};
#endif
